package com.beiding.t;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.beiding.jsonanalyzer.Analyzer;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;

import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 丁常磊
 * @date 2021/10/11 19:31
 */

public class FastRegister {
//    public static void main(String[] args) throws IOException {
//
//        FileWriter fileWriter = new FileWriter("C:\\Users\\lenovo\\Desktop\\重复注册成功.txt");
//
//        ExecutorService executorService = Executors.newFixedThreadPool(200);
//
//        Map<String, String> map = new ConcurrentHashMap<>();
//
//        List<String> all = new ArrayList<>();
//
//        for (int i = 0; i < 1; i++) {
//
//            Analyzer analyzer = Analyzer.read("{\n" +
//                    "    \"channel_id\": \"V3\",\n" +
//                    "    \"identifytype\": \"N\",\n" +
//                    "    \"invitedby\": \"\",\n" +
//                    "    \"mkt\": \"0001\",\n" +
//                    "    \"name\": \"dingchanglei\",\n" +
//                    "    \"nick_name\": \"dingchanglei\",\n" +
//                    "    \"reg_keyword\": \"15615634868\",\n" +
//                    "    \"reg_method\": \"2\",\n" +
//                    "    \"reg_password\": \"\"\n" +
//                    "}");
//
//            //注册手机号
//
//            Random random = new Random();
//            String phone =analyzer.getString("reg_keyword");//= "" + (random.nextInt(999) + 1000) + String.format("%03d", random.nextInt(999)) + String.format("%04d", random.nextInt(9999));
//
//            if (all.contains(phone)) {
//                continue;
//            }
//            all.addElement(phone);
//
//            analyzer.set("reg_keyword", phone);
//
//            //提交5个线程任务同时执行注册
//            for (int j = 0; j < 1; j++) {
//
//                executorService.submit(() -> {
//
//                    Analyzer request = request("http://10.161.19.53/ocm-info-webin/rest?ent_id=0&method=efuture.ocm.info.main.fastregister", analyzer);
//
//                    if ("0".equals(request.getString("returncode"))) {
//                        String executeOne = map.executeOne(phone, phone);
//
//                        if (executeOne != null) {
//                            try {
//                                fileWriter.write("重复注册成功:     " + phone + "\n");
//                                fileWriter.flush();
//                            } catch (Exception e) {
//                            }
//                            System.err.println("重复注册成功:     " + phone);
//                        }
//                    }
//
//                });
//
//            }
//        }
//    }
//
//    private static Analyzer request(String path, Analyzer body) {
//        RestTemplate restTemplate = new RestTemplate();
//        HttpHeaders httpHeaders = new HttpHeaders();
//        HttpEntity<String> entity = new HttpEntity<>(body.getContent(JSON.class).toJSONString(), httpHeaders);
//        String jsonObject = restTemplate.postForObject(path, entity, String.class);
//        return Analyzer.read(jsonObject);
//    }
//

}
